<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
img{
    position: absolute;
    left:200px;
    top:200px
}
</style>
<body>
    <img src="./imgs/down-0.png" alt="" id="peo">
</body>
<script>
    
    man()
    function man(){      
        var left =false;
        var top =false;
        var right=false;
        var bottom =false;  
        var index =0; 
        setInterval(function(){
            if(left){
                peo.style.left =peo.offsetLeft-10 +'px'
                direction('left')
            }else if(top){
                peo.style.top=peo.offsetTop-10 +'px'
                direction('up')
            }else if(right){
                peo.style.left=peo.offsetLeft+10 +'px'
                direction('right')
            }else if(bottom){
                peo.style.top=peo.offsetTop+10 +'px'
                direction('down')
            }
        },30)

        document.onkeydown=function(e){
        var e=e || window.event;
        switch(e.keyCode){
            case 37 :
               left=true
                break;
            case 38:
                top =true
                break;
            case 39:
                right =true
                break
            case 40:
                bottom =true
                break
        }
    }
    document.onkeyup=function(e){
        var e=e || window.event;
        switch(e.keyCode){
            case 37 :
               left=false
                break;
            case 38:
                top =false
                break;
            case 39:
                right =false
                break
            case 40:
                bottom =false
                break
        }
    }
    function direction(dir){
        index++;
        if(index>=4){
            index =0
        }
        peo.src=`./imgs/${dir}-${index}.png`
    }
    }
    

</script>
</html>